package com.clerkq.FP
{
	import com.clerkq.FP.model.FlipPageModel;
	import com.clerkq.FP.model.PageInfo;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Stage;
	
	public class FlipPage extends UIObject implements IDisposable
	{
		private var _model:FlipPageModel;
		private var _engine:FlipEngine;
		private var _stage:Stage;
		
		//======================================================================
		//						Method
		//======================================================================
		public function FlipPage(stage:Stage)
		{
			super();
			_stage = stage;
			_model = new FlipPageModel();
			_engine = new FlipEngine(_model, _stage);
			addChild(_engine);
		}
		
		// contentName: C1, C2, 1, 2, ...    contentPath: 图片的路径
		public function addPage(contentName:String, contentPath:String):void{
			var pageInfo:PageInfo = new PageInfo();
			pageInfo.itemName = contentName;
			pageInfo.itemPath = contentPath;
			_model.addPage(pageInfo);
		}
		
		public function start(pageIndex:Number = 0):void{
			_engine.start(pageIndex);
		}
		
		public function flipPrevPage(angle:Number):void{
			_engine.flipPrevPage(angle);
		}
		
		public function flipNextPage(angle:Number):void{
			_engine.flipNextPage(angle);
		}
		
		public function flipToPage(index:int, angle:Number, contInterval:int):void{
			_engine.flipToPage(index, angle, contInterval);
		}
		
		//======================================================================
		//						Set Parameters
		//======================================================================
	    public function get hasCover():Boolean					{		return _model.hasCover;		}		
		public function set hasCover(value:Boolean):void		{
					_model.hasCover = value;
		}
		
		public function setSize(pageWidth:Number = 115, pageHeight:Number = 150):void{
			_model.pageWidth = pageWidth;
			_model.pageHeight = pageHeight;
		}
		
		public function setAccRatio(drag:Number, move:Number, fold:Number, unfold:Number):void{
			_model.accRatio.drag = drag;
			_model.accRatio.move = move;
			_model.accRatio.fold = fold;
			_model.accRatio.unfold = unfold;
		}
		
		public function setFlipArea(	top:Boolean = true, 
										bottom:Boolean = true, 
										side:Boolean = true, 
										cornerWidth:Number = 30, 
										cornerHeight:Number = 20, 
										sideWidth:Number = 10, 
										flipMarginX:Number = 0, 
										flipMarginY:Number = 0):void{
			_model.flipArea.setValue(top, bottom, side, cornerWidth, cornerHeight, sideWidth, flipMarginX, flipMarginY);
		}
		
		public function setVisiblePages(left:uint, right:uint, flip:uint):void{
			_model.visiblePages.setValue(left, right, flip);
		}
		
		public function resetModel():void{
			_model = new FlipPageModel();
			
			if(_engine){
				this.removeChild(_engine);
				_engine.Dispose();
			}
			_engine = new FlipEngine(_model, _stage);
			addChild(_engine);
		}
		
		public function Dispose():void{
			_model = null;
			_engine.Dispose();
			removeAllChilds();
		}
		
		// Get and Set
		public function get pageCount():int{
			return _model.pageList.length;
		}
		public function get curIndex():int{
			return _engine.curIndex;
		}

	}
}